﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BT_BieuThuc_Nhom13.Expressions
{
    public class NormialExpr : Expression
    {
        double a;
        double n;
        private NormialExpr(double _a, double _n)
        {
            a = _a;
            n = _n;
        }

        public static Expression CreateObject(double _a, double _n)
        {
            if (_a == 0 || _n == 0)
            {
                return ConstExpr.CreateObject(_a);
            }

            return new NormialExpr(_a, _n);
        }

        public override double Evaluate(double x)
        {
            return a * (double)Math.Pow(x, n);
        }

        protected override Expression CreateDerive()
        {
            return new NormialExpr(a, n - 1);
        }

        public override string ToString()
        {
            return String.Format("{0}x^{1}", a, n);
        }
    }
}
